﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace TCG.Engine.Core
{
    public class Deck
    {
        List<Card> cards = new List<Card>();
        List<Card> sideboard = new List<Card>();

        public List<Card> Sideboard
        {
            get { return sideboard; }
        }

        public string Id { get; set; }
        public string Title { get; set; }

        public void AddCard(Card c)
        {
            cards.Add(c);
        }

        public void AddCard(Card c, int count)
        {
            for (int i = 0; i < count; i++)
                cards.Add(c);
        }

        public void Shuffle()
        {

        }
        public void Remove(Card c)
        {
            cards.Remove(c);
        }

        public int Count { get { return cards.Count; } }


        public Card Draw()
        {
            if (!cards.Any())
            {
                cards = sideboard;
                sideboard = new List<Card>();
                Shuffle();
            }
            var result = cards.Last();
            cards.Remove(result);

            return result;
        }

        public Card Contains(string cardId)
        {
            var card = cards.FirstOrDefault(c => c.Info.Id == cardId);
            return card != null ? card : sideboard.FirstOrDefault(c => c.Info.Id == cardId);
        }

        public Card GetCard(string id)
        {
            var result = cards.First(c => c.Info.Id == id);
            cards.Remove(result);
            return result;
        }
    }
}
